package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.IUserDao;
import com.cn.wanxi.dao.impl.UserDaoImpl;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.IUserService;

import java.util.List;

public class UserServiceImpl implements IUserService {
    IUserDao userDao = new UserDaoImpl();

    @Override
    public int addUser(UserModel userModel) {
        if (userIsExist(userModel.getUsername()) == false) {//如果为空，则该用户名为未被占用，false
            int count = userDao.addUser(userModel);
            System.out.println("count=" + count);
            return count;
        }else
            return 4;
        }

        @Override
        public int updateUser (UserModel userModel){
            return userDao.updateUser(userModel);
        }

        @Override
        public int deleteUser ( int id){
            return userDao.deleteUser(id);
        }

        @Override
        public UserModel getUser ( int id){
            return userDao.getUser(id);
        }

    @Override
    public List<UserModel> getUserList() {
        return userDao.getUserList();
    }

    @Override
        public List<UserModel> getUserList (int pageNum,int pageSize) {
            return userDao.getUserList(pageNum,pageSize);
        }

    @Override
    public List<UserModel> getUserList(int pageNum, int pageSize, String sort) {
        return userDao.getUserList(pageNum, pageSize, sort);
    }

    @Override
        public boolean userIsExist (String username){
            UserModel userModel = userDao.getUserByUsername(username);
            if (userModel == null) {//如果为空，则该用户名为未被占用，false
                return false;
            } else//如果不为空，则该用户名被已占用，true
                return true;
        }

    @Override
    public List<UserModel> searchUser(String sql) {
        return userDao.searchUser(sql);
    }

    @Override
    public UserModel login(UserModel userModel) {
        return userDao.login(userModel);
    }

    @Override
    public long getUserCount() {
        return userDao.getUserCount();
    }


}
